<template>
	<view class="route-quicksale">
		<view class="cont">
			<view class="inner">
				<view class="have" v-if="goodsList.length">
					<view class="item" v-for="(item,index) in goodsList" :key="index" @click="handleDetail(item)">
						<view class="item-top">
							<view class="top-left">
								<image class="img" :src="item.image[0]" mode="aspectFill"></image>
							</view>
							<view class="top-right">
								<view class="name">
									{{item.title}}
								</view>
								<view class="danpinContent">
									{{item.content}}
								</view>
								<view class="price">
									<text>￥{{item.price}}</text>
									<view class="">
										<u-button color="#28E06E" size="small" type="primary" icon="shopping-cart" text="立即购买"></u-button>
									</view>
								</view>
							</view>
						</view>

					</view>
					<u-loadmore :status="status" />
				</view>
				<view class="none" v-else>
					<u-empty text="暂无商品" mode="list"></u-empty>
				</view>

			</view>
		</view>

	</view>
</template>

<script setup>
	import handleCache from "@/utils/cache.js"
	import {
		quickSaleApi,

	} from '@/api/index.js'
	import {
		ref,
		computed,

	} from 'vue'
	import {
		onReady,
		onShow,
		onLoad,
		onReachBottom
	} from '@dcloudio/uni-app'
	import {
		forEach
	} from "lodash";
	const userInfo = ref()
	const currentPage = ref(1)
	const totalPage = ref(0)
	const pageSize = ref(20)
	const status = ref('nomore')
	const goodsList = ref([])
	const loadStatus = ref('nomore')
	onShow(() => {
		userInfo.value = handleCache.get('userInfo')
		getData()
	})
	const getData = () => {
		currentPage.value = 1
		let req = {
			shanghuid: userInfo.value.shanghuid,
			pageNo: currentPage.value,
			pageSize: pageSize.value,
		}
		uni.showLoading({
			title: '加载中'
		})
		quickSaleApi.danpinlist(req).then((res) => {
			uni.hideLoading()
			totalPage.value = res.data.totalPage || 0;

			for (var i = 0; i < res.data.data.length; i++) {
				console.log(res.data.data[i].image);
				if (res.data.data[i].image != '') {
					var links = res.data.data[i].image.split(",");
					res.data.data[i].image = links;
					res.data.data[i].content = unescape(res.data.data[i].content.replace(/\\/g, "%"));
				}
			}


			goodsList.value = res.data.data || []
			if (totalPage.value > currentPage.value) {
				loadStatus.value = 'loadmore'
			} else {
				loadStatus.value = 'nomore'
			}
		})
	}
	const loadData = () => {
		if (currentPage.value >= totalPage.value) return;
		loadStatus.value = 'loading'
		currentPage.value = ++currentPage.value

		let req = {
			shanghuid: userInfo.value.shanghuid,
			pageNo: currentPage.value,
			pageSize: pageSize.value,
		}
		uni.showLoading({
			title: '加载中'
		})
		quickSaleApi.danpinlist(req).then((res) => {
			uni.hideLoading()
			goodsList.value = [...goodsList.value, ...res.data.data]
			if (totalPage.value > currentPage.value) {
				loadStatus.value = 'loadmore'
			} else {
				loadStatus.value = ' nomore'
			}
		})
	}
	const handleDetail = (data) => {
		uni.navigateTo({
			url: `/pages/quicksale/quicksale?id=${data.id}&shanghuid=${userInfo.value.shanghuid}`
		})
	}
</script>

<style lang="scss" scoped>
	.route-quicksale {
		min-height: 100vh;
		background-color: #f5f5f5;
		padding-bottom: 150rpx;

		.cont {
			padding: 30rpx 24rpx 0 24rpx;

			.inner {
				.have {
					.item {
						background-color: #fff;
						padding: 20rpx;
						border-radius: 8rpx;
						margin-bottom: 30rpx;

						.item-top {
							display: flex;

							.top-left {
								flex-shrink: 0;
								width: 190rpx;
								height: 190rpx;
								border-radius: 8rpx;
								overflow: hidden;

								.img {
									display: block;
									width: 100%;
									height: 100%;
								}
							}

							.numcont {
								display: flex;
								padding-top: 20rpx;

								.citem {
									display: flex;
									margin-right: 30rpx;
									font-size: 26rpx;

									.label {
										color: #999;
									}
								}
							}

							.top-right {
								flex: 1;
								padding-left: 40rpx;

								.name {
									font-size: 32rpx;
									font-weight: 700;
								}

								.danpinContent {
									overflow: hidden;
									text-overflow: ellipsis;
									display: -webkit-box;
									-webkit-line-clamp: 2;
									-webkit-box-orient: vertical;
									color: #a6a6a6;
									font-size: 24rpx;
									margin-top: 10rpx;
								}

								.price {
									font-size: 36rpx;
									margin-top: 30rpx;
									color: #ED2920;
									font-weight: 700;
									display: flex;
									justify-content: space-between;
								}
							}
						}

						.item-footer {
							display: flex;
							justify-content: flex-end;

							button {
								padding: 0;
								margin: 0;
								line-height: 38rpx;
							}

							button::after {
								border: none;
							}

							.text-btn {

								// margin-left: 10rpx;

								background-color: transparent;
								padding: 10rpx 20rpx;
								font-size: 28rpx;
							}

							.color1 {
								color: #2979ff;
							}

							.color2 {
								color: #fa3534;
							}

							.color3 {
								color: #19be6b;
							}
						}

					}
				}

				.none {
					padding-top: 10vh;
				}
			}
		}

		.footer {
			position: fixed;
			bottom: 0;
			left: 0;
			z-index: 10;
			width: 100%;
			background: #fff;
			padding: 10rpx 20rpx 0 20rpx;
			height: 120rpx;
			box-shadow: 0 0 4px 2px #eeecef;
			box-sizing: border-box;

			.btn {
				width: 100%;
				font-size: 28rpx;
				height: 90rpx;
				border-radius: 20rpx;
				color: #fff;
			}
		}
	}
</style>